package com.pinyougou.shop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.common.PageResult;
import com.pinyougou.pojo.Goods;
import com.pinyougou.service.GoodsService;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/goods")
public class GoodsController
{
    @Reference(timeout = 10000)
    private GoodsService goodsService;


    @GetMapping("/findByPage")
    public PageResult findByPage(Goods goods, Integer page, @RequestParam(defaultValue = "10") Integer rows)
    {
        //获取sellerId
        String sellerId = SecurityUtils.getSubject().getPrincipal().toString();
        goods.setSellerId(sellerId);
        return goodsService.findByPage(goods,page,rows);
    }


    @PostMapping("/save")
    public boolean save(@RequestBody Goods goods)
    {
        try
        {
            goodsService.save(goods);
            return true;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return false;
    }

}